package servlet;

import dao.CartDao;
import dao.GoodsDao;
import entity.Cart;
import entity.Goods;
import entity.Order;
import entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;

@WebServlet("/myCartServlet")
public class myCartServlet extends HttpServlet {
	
	@Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, IOException {
        doGet(request, response);
    }
	@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, IOException {

		System.out.println("-----------myCartServlet------------");
		User user = (User) request.getSession().getAttribute("user");
		if (user == null){
			request.getSession().setAttribute("errorMsg", "请先登录！");
			response.sendRedirect("frontend/index.jsp");
			return;
		}else {
			Integer userId = user.getUserId();
			CartDao dao = new CartDao();
			List<Cart> myCartList = dao.selectMyCart(userId);
			request.getSession().setAttribute("myCartList",myCartList);
			System.out.println("Cart List: " + myCartList);
			response.sendRedirect("frontend/cart.jsp");
		}

	}


}
